package com.heiko.myopenglrecord2

import android.content.Context
import android.opengl.GLSurfaceView
import android.util.AttributeSet
import androidx.lifecycle.LifecycleOwner
import com.heiko.myopenglrecord2.utils.CameraHelper

class CameraView(context: Context, attr: AttributeSet) : GLSurfaceView(context, attr) {
    init {
        setEGLContextClientVersion(2)

        val renderer = CameraRender(this)
        setRenderer(renderer)

        val lifecycleOwner = context as LifecycleOwner
        CameraHelper(lifecycleOwner, renderer)

        //注意必须在setRenderer后面
        //renderMode = RENDERMODE_CONTINUOUSLY //自動刷新，大概16ms自動回調一次onDrawFrame方法
        renderMode = RENDERMODE_WHEN_DIRTY //手动刷新，調用requestRender()
    }
}